//
//  GPAccountListViewController.m
//  大股票
//
//  Created by mac on 2019/9/5.
//  Copyright © 2019 apple. All rights reserved.
//

#import "GPAccountListViewController.h"
#import "GPAccountList.h"
#import "GPAccountModel.h"
#import "DGPUtil.h"

@interface GPAccountListViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic,strong) NSArray *sourceArr;
@end

@implementation GPAccountListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _sourceArr = [GPAccountModel mj_objectArrayWithKeyValuesArray:[USER_DEFAULTS objectForKey:[NSString stringWithFormat:@"%@_topList",[DGPUtil getCurrentUserID]]]];
    
    NSMutableArray * tmpArr = [NSMutableArray arrayWithArray:_sourceArr];
    NSArray *arr = [[tmpArr reverseObjectEnumerator] allObjects];
    _sourceArr = arr;
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableFooterView = [UIView new];
    [self.tableView registerNib:[UINib nibWithNibName:@"GPAccountList" bundle:nil] forCellReuseIdentifier:@"GPAccountList"];
    if (_sourceArr.count == 0) {
        [MBProgressHUD showInformation:@"暂无数据" toView:self.view andAfterDelay:HUD_TIME];
    }
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _sourceArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    GPAccountList *cell = [GPAccountList cellWithTableView:tableView :indexPath];
    GPAccountModel *model = self.sourceArr[indexPath.row];
    if (model.type==1) {
        cell.name.text = @"充值";
        cell.status.textColor = [UIColor blackColor];
        cell.status.text = model.status;
        cell.money.text = [NSString stringWithFormat:@"+%.2f",[model.money floatValue]];
    }else if (model.type==2){
        cell.name.text = @"提现";
        cell.status.textColor = UIColorFromRGB(0xFF4E13);
        cell.status.text = model.status;
        cell.money.text = [NSString stringWithFormat:@"-%.2f",[model.money floatValue]];
    }else if (model.type==3){
        cell.name.text = @"消费";
        cell.status.textColor = [UIColor blackColor];
        cell.status.text = model.status;
        cell.money.text = [NSString stringWithFormat:@"+%.2f",[model.money floatValue]];
    }
    cell.date.text = model.date;
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 82;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
